<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        
        #div {
            width: 600px;
            height: 400px;
            background-color: #fafafa;
            margin: 0 auto;
            border: 1px solid #333;
            overflow: scroll;
        }
        #cont {
            width: 300px;
            height: 2000px;
            background-color: #ccc;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div id="div">
        <div id="cont">
            开头
        </div>
    </div>
</body>
<script>
    div.onscroll = e =>  {
        console.dir(div.scrollTop)
    }
    window.onbeforeunload = e => {
        console.log('div.scrollTop', div.scrollTop)
        localStorage.setItem('top', div.scrollTop)
    };
    div.scrollTop = localStorage.getItem('top');
    localStorage.removeItem('top')
</script>
</html>